import {
  inspection
} from '../../api/api.js';
const app = getApp();
import util from '../../utils/util.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    parameter: {
      'navbar': '1',
      'return': '1',
      'title': '验货收货',
      'color': true,
      'class': '0'
    },
    showModalStatus: true,
    refund_reason_wap_img: [], //配送清单
    refund_reason_wap_img_2: [], //货物照片
    refund_reason_wap_img_3: [], //破损照片
  },

  know: function() {
    this.setData({
      showModalStatus: false
    })
  },
  // 配送清单
  /**
   * 删除图片
   * 
   */
  DelPic: function(e) {
    var index = e.target.dataset.index,
      that = this,
      pic = this.data.refund_reason_wap_img[index];
    that.data.refund_reason_wap_img.splice(index, 1);
    console.log(that.data.refund_reason_wap_img)
    that.setData({
      refund_reason_wap_img: that.data.refund_reason_wap_img
    });
  },

  /**
   * 上传文件
   * 
   */
  uploadpic: function() {
    var that = this;
    util.uploadImageOne('upload/image', function(res) {
      that.data.refund_reason_wap_img.push(res.data.url);
      console.log(that.data.refund_reason_wap_img)
      that.setData({ refund_reason_wap_img: that.data.refund_reason_wap_img });
    });
  },
  // 配送清单结束
  //  货物照片
  /**
   * 删除图片
   * 
   */
  DelPic_2: function(e) {
    var index = e.target.dataset.index,
      that = this,
      pic = this.data.refund_reason_wap_img_2[index];
    that.data.refund_reason_wap_img_2.splice(index, 1);
    console.log(that.data.refund_reason_wap_img_2)
    that.setData({
      refund_reason_wap_img_2: that.data.refund_reason_wap_img_2
    });
  },

  /**
   * 上传文件
   * 
   */
  uploadpic_2: function() {
    var that = this;
    util.uploadImageOne('upload/image', function(res) {
      that.data.refund_reason_wap_img_2.push(res.data.url);
      console.log(that.data.refund_reason_wap_img_2)
      that.setData({ refund_reason_wap_img_2: that.data.refund_reason_wap_img_2 });
    });
  },
  //  货物照片结束
  // 破损照片
  /**
   * 删除图片
   * 
   */
  DelPic_3: function(e) {
    var index = e.target.dataset.index,
    that = this,
    pic = this.data.refund_reason_wap_img_3[index];
    that.data.refund_reason_wap_img_3.splice(index, 1);
    console.log(that.data.refund_reason_wap_img_3)
    that.setData({
      refund_reason_wap_img_3: that.data.refund_reason_wap_img_3
    });
  },

  /**
   * 上传文件
   * 
   */
  uploadpic_3: function() {
    var that = this;
    util.uploadImageOne('upload/image', function(res) {
      that.data.refund_reason_wap_img_3.push(res.data.url);
      console.log(that.data.refund_reason_wap_img_3)
      that.setData({ refund_reason_wap_img_3: that.data.refund_reason_wap_img_3 });
    });
  },
  // 破损照片结束
  inspection: function() {
    var that = this
    if(that.data.refund_reason_wap_img == '' || that.data.refund_reason_wap_img == null){
      return app.Tips({title:"请上传配送清单！"});
    }
    if(that.data.refund_reason_wap_img_2 == '' || that.data.refund_reason_wap_img_2 == null){
      return app.Tips({title:"请上传货物照片！"});
    }
    if(that.data.refund_reason_wap_img_3 == '' || that.data.refund_reason_wap_img_3 == null){
      return app.Tips({title:"请上传破损照片！"});
    }
    inspection(that.data.refund_reason_wap_img.join(','), that.data.refund_reason_wap_img_2.join(','), that.data.refund_reason_wap_img_3.join(','), app.globalData.userInfo.uid).then(res => {
      if(res.status == '200'){
        return app.Tips({title:"提交成功！"});
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})